import {computed} from "vue";
import store from "@/stores";
import type {RouteLocationNormalized} from "vue-router";
import {findMenuByUrl} from "@/utils/tabs";


const title = computed(() => {
    return store.appStore.theme.title;
})

export default function getPageTitle(route: RouteLocationNormalized) {
    if (route) {
        let pageTitle = route.meta.title;
        if (route.meta.multiplex) {
            const find = findMenuByUrl(route.fullPath);
            if (find) {
                pageTitle = find.meta.title;
            }
        }
        if (pageTitle) {
            return pageTitle + " - " + title.value;
        } else {
            return title.value;
        }
    }
    return title.value;
}
